﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using SharedCode;
using AdminModule.IndexMarkServiceReference;

namespace AdminModule.ViewModels
{
    public class MainVM : ViewModelBase
    {
        IndexMarkServiceClient client = new IndexMarkServiceClient();

        private ObservableCollection<AdmTerm> terms = new ObservableCollection<AdmTerm>();
        public ObservableCollection<AdmTerm> Terms
        {
            get
            {
                return this.terms;
            }
            set
            {
                this.terms = value;
            }
        }

        public MainVM()
        {
            client.GetAdmTermsCompleted += new EventHandler<GetAdmTermsCompletedEventArgs>(client_GetAdmTermsCompleted);
        }

        public void LoadTerms()
        {
            client.GetAdmTermsAsync();
        }

        void client_GetAdmTermsCompleted(object sender, GetAdmTermsCompletedEventArgs e)
        {
            terms.Clear();
            foreach (var t in e.Result)
            {
                terms.Add(t);
            }
            this.LoadCompletedInit(typeof(AdmTerm));
        }
    }
}
